const UserTokenKey = "User-Token-Cache";

export default class User {

    static screenHeight:Number =70;
    static topSafeArea:Number = 40;
    ///是否自动登录
    static isAutoLogin:Boolean = false;


 

    ///连接设备的蓝牙协议id
    static connectDebiceBluetoothUnionid = '';

      ///是否展示进入设备联机的loading
      static isShowIntoDeviceLoading:Boolean = false;

      ///是否已初始化蓝牙设备
      static isInitBlueTooth:Boolean = false;

      ///是否已经连接蓝牙设备(这个以能够真正拿到实时数据，非连上蓝牙就当做成功)
      static isConnectedBlueTooth:Boolean = false ;
       ///是否已经连接蓝牙设备(这个是连上蓝牙就当做成功的临时中间状态)
       static isTempConnectedBlueTooth:Boolean = false ;
      ///连接的蓝牙设备
      static currentConnectedBlueTooth =  {} as any;
        ///是否已经接收到实时数据
        static isReceivedRuntimeData = false;
        ///是否需要刷新我的设备列表
      static isNeedRefreshEquipmentList = false;

      ///设备详情是否可以监听蓝牙改变数据
      static canDeviceDetailListenBleDate = false;

         ///实时电压数组
         static voltageList =  [] as any;
        ///实时转速数组
        static speedList =  [] as any;
        ///实时电功率数组
         static powerList =  [] as any;
        ///实时油门数组
        static acceleratorList =  [] as any;
        ///实时油量数组
         static oilCountList =  [] as any;    
        ///实时运行时间数组
        static runtimeList =  [] as any;    

      ///播放视频
      static choosedPlayVideo={

      } as any;


      ///当前连接的硬件实体类
      static currentConnectedEquipment = {
        deviceID:'',
        canSendMaintainTips:false, //是否可以上传维修信息
        warning_tips:'',///上一次记录的维修信息
        oil_lower_warn:'',  //机油少报警
        battery_electricity_lower_warn:'',  //电池电量低报警
        temperature_higher_warn:'',  //温度高报警
        gas_lower_warn:'',  //汽油少报警
      } as any;

      ///当连接蓝牙时临时选中的设备ID
      static tempChoosedEquipDeviceId = '';
        ///当连接蓝牙时临时选中的设备
        static currentTempChoosedEquipment =  null as any;

        ///查看详情选中的设备
        static choosedShowDetailEquip = null as any;



      ///蓝牙回写数据实体类
      static bluetoothCallbackData = {
        string_voltage_variable:'', ///所有变量范围接收字符串
        string_voltage_level:'', ///电压等级接收字符串
        string_runtime_data:'', ///实时数据接收字符串
        string_ble_version_data:'', ///蓝牙版本号接收字符串
        string_ble_data_status_data:'', ///使能变量状态接收字符串
        string_device_union_id_data:'', ///设备唯一id的接收字符串
        string_control_version_data:'', ///控制器版本号的接收字符串

      } as any;

 ///当前选中设备的蓝牙数据
    static currentChoosedMachineBleData = {
        frequency:'',//频率
        oil_mass:'',//油量
        single_run_time:'',//单次运行时间
        total_run_time:'',//累计运行时间
        single_elec_power:'',//单次发电功率
        total_power_power:'',//累计发电功率
        blue_tooth_version:'',//蓝牙版本
        control_version:'',//控制版本
        warn_status_tips:'',//报警状态开关量
        is_hide_pedal_singal_model:'',//是否隐藏脚踏信号
        is_running:false,//是否正在运行
        engine_run_status:'',//发动机运行状态
        work_mode:'',//工作模式
        work_mode_name:'',//工作模式中文名
        control_status:'',//控制状态
        pedal_signal_model:'',//脚踏信号模式
        self_start_voltage:'',//自启电压
        self_stop_mode:'',//自停模式
        start_stop_tag:'',//启停模式
        electricity_voltage:'',//发电电压
        voltage_level_range:'',//电压等级
        oil_type:'',//燃料类型
        max_voltage:'',//最大电压范围
        min_voltage:'',//最小电压范围
        max_power:'',//最大功率范围
        min_power:'',//最小功率范围
        max_speed:'',//最大转速范围
        min_speed:'',//最小转速范围
        max_gas:'',//最大油门范围
        min_gas:'',//最小油门范围
        self_start_voltage_max:'',//最大自启电压
        self_start_voltage_min:'',//最小自启电压
        electricity_voltage_max:'',//最大发电电压
        electricity_voltage_min:'',//最小发电电压
        curr_voltage:'',//当前电压
        curr_power:'',//当前功率
        curr_speed:'',//当前转速
        curr_gas:'',//当前油门
        curr_temperature:'',//当前温度
        curr_oil_count:'',//当前油量
        curr_voltage_level:'',//当前电压等级
        battery_electricity_lower_warn:'',//电池电量低报警
        control_warn:'',//控制器报警
        temperature_higher_warn:'',//温度高报警
        oil_lower_warn:'',//机油少报警
        gas_lower_warn:'',//汽油少报警
        is_commend_hidden_voltage:false,//是否展示电压
        is_commend_hidden_power:false,//是否展示功率
        is_commend_hidden_frequency:false,//是否展示频率
        is_commend_hidden_single_run_time:false,//是否展示单次运行时间
        is_commend_hidden_total_run_time:false,//是否展示累计运行时间
        is_commend_hidden_single_electricity_power:false,//是否展示单次发电功率
        is_commend_hidden_total_electricity_power:false,//是否展示累计发电功率
        is_commend_hidden_speed:false,//是否展示转速
        is_commend_hidden_gas:false,//是否展示油门
        is_commend_hidden_oil_left:false,//是否展示机油剩余量
        is_commend_hidden_warn_status_num:false,//是否展示报警状态开关量
        is_commend_hidden_engine_run_status:false,//是否展示发动机运行状态
        is_commend_hidden_gas_left:false,//是否展示汽油剩余量
        is_commend_hidden_temperature:false,//是否展示温度
        is_commend_hidden_work_mode:false,//是否展示工作模式
        is_commend_hidden_control_way:false,//是否展示控制方式
        is_commend_hidden_start_tag:false,//是否展示启动标志
        is_commend_hidden_self_start_voltage:false,//是否展示自启电压
        is_commend_hidden_self_stop_mode:false,//是否展示自停模式
        is_commend_hidden_electricity_voltage:false,//是否展示发电电压
        is_commend_show_power_level:false,//是否展示电压等级
        is_commend_show_foot_signal_model:false,//是否展示脚踏信号模式
        is_new_version_equipment:false,//是否新版本设备
        is_active:'',//是否激活
        actDate:'',//激活时间
        actDateStr:'',//激活时间
        trial_time:0,//试用倒计时时间
        actstatus:false,//是否激活
        forceStopTime:'0',//强制自熄时间
        is_lng:false,//是否是lng设备

    }



    static setObject (obj:any) {
        for(const i in  obj){
            this.set(i,obj[i])
        }
    }

    static get (key:string) {
        return this.isAutoLogin ? window.localStorage.getItem(key) : window.sessionStorage.getItem(key)
    }

    

    static set (key:string, value:any) {
        if( this.isAutoLogin ) {
            return window.localStorage.setItem(key, value)
        }else {
            return window.sessionStorage.setItem(key, value)
        }
    }

    //获取用户手机号
    static getUserMobile(){
        return this.get('userMobile')
    }
    //用户名
    static getUserName(){
        return this.get('userName')
    }

     //微信授权的openid
     static getWxOpenid(){
        return this.get('openId')
    }


    //拿到token
    static getToken(){
        // return 'A742EEE9E61D6F7A1C96C5FE9C163C57EA53E059'
        // return 'EA9F27F744388AC95C7CC5DFA576827A1C23F29D'
        return uni.getStorageSync(UserTokenKey)
    }
    //赋值token
    static setToken(token:string){
        uni.setStorageSync(UserTokenKey,token)
    }
    //清除token
    static removeToken(){
        uni.removeStorageSync(UserTokenKey)
    }



    static isNotLogin(){

        let token =  this.getToken()


        if(token === null || token.length < 1 ||  token === 'undefined'){
            return true
        }else{
            return false
        }
    }



    //清除缓存
    static clearLocalUser () {
        this.removeToken()
        if (this.isAutoLogin) {
            return this.localStorageClear()
        } else {
            return this.sessionClear()
        }
    }
    
    //清除长久保存的网页数据
    static localStorageClear () {
        window.localStorage.clear()
    }
    //清除本次会话中的网页数据
    static sessionClear () {
        window.sessionStorage.clear()
    }


    ///方法改变
static macthBluetoothDataChanged=null as any;
    



}
